/*  
     PlAr is Platform Arena: a 2D multiplayer shooting game
     Copyright (c) 2009 Ragagnin Antonio <spocchio@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package plar.elements;

import java.awt.Point;
import java.awt.Polygon;

import plar.core.Element;
import plar.core.Level;
import plar.core.defaultElements.Ammo;
import plar.core.defaultElements.Block;
import plar.core.defaultElements.Elevator;
import plar.core.defaultElements.SpawnPoint;

public class Level0 extends Level implements Runnable {

	int tile = 45;

	public Level0() {
		SpawnPoint r = new SpawnPoint();
		r.setPosition(new Point(700, 100));
		AddElement(r);

		r = new SpawnPoint();
		r.setPosition(new Point(400, 100));

		AddElement(r);

		addBlockSet(new Point(10, 1010), 81);
		elements.remove(elements.size() - 1);
		elements.remove(elements.size() - 1);

		{
			Point p = new Point(35, 960);
			Block bb = new Block();
			bb.setSize(new Point(25, 118));
			bb.setStaticSprire("res/block/blockcbl.png");

			bb.setPosition(p);
			AddElement(bb);

			for (int i = 0; i < 30; i++) {

				Block bm = new Block();
				bm.setStaticSprire("res/block/blockcr.png");
				bm.setSize(new Point(25, 118));
				// bm.getCurrentSpriteSet().get(0).offset=new Point(0,-17);
				bm.setPosition(new Point(p.x, p.y - 118 * (i + 1)));
				AddElement(bm);
			}

		}

		{
			Point p = new Point(4100, 960);
			Block bb = new Block();
			bb.setSize(new Point(25, 118));
			bb.setStaticSprire("res/block/blockcbr.png");

			bb.setPosition(p);
			AddElement(bb);

			for (int i = 0; i < 30; i++) {

				Block bm = new Block();
				bm.setStaticSprire("res/block/blockcr.png");
				bm.setSize(new Point(25, 118));
				// bm.getCurrentSpriteSet().get(0).offset=new Point(0,-17);
				bm.setPosition(new Point(p.x, p.y - 118 * (i + 1)));
				AddElement(bm);
			}

		}

		addBlockSet(new Point(200, 450), 1);
		addBlockSet(new Point(400, 450), 10);
		addBlockSet(new Point(2800, 450), 10);
		addBlockSet(new Point(1200, 450), 10);
		addBlockSet(new Point(2000, 550), 10);

		Elevator n = new Elevator();
		((Polygon) n.getProperty("path")).addPoint(1205, 550);
		((Polygon) n.getProperty("path")).addPoint(3700, 550);
		n.setPosition(new Point(1201, 700));
		n.setStaticSprire("res/elevator.png");
		n.getCurrentSpriteSet().get(0).offset = new Point(0, -20);
		AddElement(n);

		addBlockSet(new Point(90, 695), 1);

		addBlockSet(new Point(230, 950), 1);

		addBlockSet(new Point(2800, 850), 1);
		addBlockSet(new Point(1000, 950), 2);
		addBlockSet(new Point(2000, 950), 2);
		addBlockSet(new Point(1500, 850), 3);

		addBlockSet(new Point(3900, 700), 3);

	}

	public void addBlockSet(Point p, int l) {

		for (int i = 0; i < l; i++) {

			Block bm = new Block();
			bm.setStaticSprire("res/block/blockm.png");
			bm.setSize(new Point(50, 85));
			bm.getCurrentSpriteSet().get(0).offset = new Point(0, -17);
			bm.setPosition(new Point(p.x + 50 * (i + 1)-15, p.y));
			AddElement(bm);
		}
		Block br = new Block();
		br.setSize(new Point(6, 85));
		br.setPosition(new Point(p.x + 50 * (l + 1), p.y));
		br.setStaticSprire("res/block/blockr.png");
		br.getCurrentSpriteSet().get(0).offset = new Point(-15, -17);
		br.getCurrentSpriteSet().get(0).size = new Point(25, 85);

		AddElement(br);

		Block bl = new Block();
		
		bl.setStaticSprire("res/block/blockl.png");
		//bl.setSize(new Point(50, 85));
		//bl.getCurrentSpriteSet().get(0).offset = new Point(0, -17);
		bl.setSize(new Point(50, 85));
		bl.getCurrentSpriteSet().get(0).offset = new Point(-15, -17);
		bl.setPosition(p);
		AddElement(bl);

	}

	public void run() {
		super.run();
		Double x = Math.random();
		if (x < 0.002) {
			Element a = new Ammo();
			a.setPosition(new Point(200+((int)(Math.random()*2000)), 390));
			AddElement(a);
		}// else Common.info(x.toString());

	}

}
